package core.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author iva0512
 * @version 1.0
 * @date 16-10-27
 * @email iva0512@gmail.com
 * @package core.web.controller
 * @project software
 */
public abstract class BaseController {

	protected void writeJSON(HttpServletResponse response, String json) throws IOException {
		response.setContentType("application/json;charset=utf-8");
		response.getWriter().write(json);
	}

	protected void writeJSON(HttpServletResponse response, Object obj) throws IOException {
		response.setContentType("application/json;charset=utf-8");
		// fastjson
		//response.getWriter().write(JSON.toJSONString(obj, SerializerFeature.WriteMapNullValue));
		// jackson
		response.getWriter().write((new ObjectMapper()).writeValueAsString(obj));
	}
}
